<template>
  <el-dialog class="edit-box" :title="dialog.title" :visible.sync="dialog.visible" append-to-body top="5vh"
             width="1000px">
    <div ref="print" class="cyui-resume">
      <div class="cyui-resume-hd">
        <div class="cyui-logo">
          <img src="../../../../assets/resume/img_011.png" alt="">
        </div>
        <div class="cyui-userinfo">
          <div class="cyui-userinfo-avatar">
            <img @load="imgLoaded"
                 :src="photoListData.length === 0 ? loadingImage2 : `${basePicPath}/tool/file/view?fileId=${photoListData[0].id}`"
                 alt="">
          </div>
          <div class="cyui-userinfo-right">
            <div class="cyui-userinfo-name">{{detailInfo.name}}</div>
            <div class="cyui-userinfo-post">{{detailInfo.postName}}</div>
          </div>
        </div>
      </div>
      <div class="cyui-resume-bd">
        <div class="cyui-resume-left">
          <div class="cyui-resume-chunk cyui-userinfo">
            <div class="cyui-resume-chunk-header">
              <div class="cyui-resume-chunk-header-title">个人信息</div>
            </div>
            <div class="cyui-resume-chunk-body">
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_001.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>性别：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.gender | genderFilter}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_002.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>学历：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.educationName}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_003.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>专业：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.professional}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_004.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>生日：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.birthday | formatTimestamp | formatDate('yyyy-MM-dd')}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_005.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>现居：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.householdRegister}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_006.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>政治面貌：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.politicalStatusName}}</span>
                </div>
              </div>
              <div class="cyui-userinfo-item">
                <div class="cyui-userinfo-icon">
                  <img src="../../../../assets/resume/img_007.png" alt="">
                </div>
                <div class="cyui-userinfo-label">
                  <span>民族：</span>
                </div>
                <div class="cyui-userinfo-value">
                  <span>{{detailInfo.nation}}</span>
                </div>
              </div>
            </div>
          </div>
          <div class="cyui-resume-chunk cyui-contact">
            <div class="cyui-resume-chunk-header">
              <div class="cyui-resume-chunk-header-title">联系方式</div>
            </div>
            <div class="cyui-resume-chunk-body">
              <div class="cyui-contact-item">
                <div class="cyui-contact-icon">
                  <img src="../../../../assets/resume/img_008.png" alt="">
                </div>
                <div class="cyui-contact-value">
                  <span>{{detailInfo.phone}}</span>
                </div>
              </div>
              <div class="cyui-contact-item">
                <div class="cyui-contact-icon">
                  <img src="../../../../assets/resume/img_009.png" alt="">
                </div>
                <div class="cyui-contact-value">
                  <span>{{detailInfo.wechatId}}</span>
                </div>
              </div>
              <div class="cyui-contact-item">
                <div class="cyui-contact-icon">
                  <img src="../../../../assets/resume/img_010.png" alt="">
                </div>
                <div class="cyui-contact-value">
                  <span>{{detailInfo.email}}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="cyui-resume-right">
          <div class="cyui-resume-chunk">
            <div class="cyui-resume-chunk-header">
              <div class="cyui-resume-chunk-header-title">自我评价</div>
            </div>
            <div class="cyui-resume-chunk-body">
              <p v-for="(item, index) in selfEvaluation" :key="index">
                {{item}}
              </p>
            </div>
          </div>
          <div class="cyui-resume-chunk">
            <div class="cyui-resume-chunk-header">
              <div class="cyui-resume-chunk-header-title">教育背景</div>
            </div>
            <div class="cyui-resume-chunk-body">
              <p v-for="(item, index) in educationExperience" :key="index">
                {{item}}
              </p>
            </div>
          </div>
          <div class="cyui-resume-chunk">
            <div class="cyui-resume-chunk-header">
              <div class="cyui-resume-chunk-header-title">工作经历</div>
            </div>
            <div class="cyui-resume-chunk-body">
              <p v-for="(item, index) in workExperience" :key="index">
                {{item}}
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog.visible = false">取消</el-button>
      <el-button type="primary" @click="handlePrint">打印</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import Vue from 'vue'
  import { isJSON } from '@/utils/utils'
  import { basePicPath, defaultPic, loadingImage2 } from '@/config/config'
  import filters from '@/filters/filters'
  import Print from '@/plugs/print' // 引入附件的js文件
  import { debounce } from 'lodash'

  Vue.use(Print) // 注册

  export default {
    name: 'RecordResume',
    mixins: [filters],
    components: {},
    data() {
      return {
        basePicPath,
        defaultPic,
        loadingImage2,
        dialog: {
          visible: false, // 是否显示
          title: '个人简历'
        },
        detailInfo: null
      }
    },
    props: {
      visible: {
        type: [Boolean],
        required: true,
        default: false
      },
      detailData: {
        type: Object,
        default() {
          return null
        }
      }
    },
    computed: {
      photoListData() {
        let { photoUrl = '' } = this.detailInfo || {}
        // console.log(this.filesToArray(photoUrl))
        return this.filesToArray(photoUrl)
      },
      selfEvaluation() {
        let { selfEvaluation = '' } = this.detailInfo || {}
        selfEvaluation = selfEvaluation || ''
        return selfEvaluation.replace(/[\r\n]/g, '$#%*&').split('$#%*&')
      },
      educationExperience() {
        let { educationExperience = '' } = this.detailInfo || {}
        educationExperience = educationExperience || ''
        return educationExperience.replace(/[\r\n]/g, '$#%*&').split('$#%*&')
      },
      workExperience() {
        let { workExperience = '' } = this.detailInfo || {}
        workExperience = workExperience || ''
        return workExperience.replace(/[\r\n]/g, '$#%*&').split('$#%*&')
      }
    },
    methods: {
      imgLoaded() {

      },
      filesToArray(data = '') { // 附件列表转成数组
        if (!data || data === 'null' || data === 'undefined') {
          return []
        } else {
          let files = data.split('@@**%%')
          files = files.filter((item) => {
            return isJSON(item)
          })
          return files.map((item) => {
            return JSON.parse(item)
          })
        }
      },
      handlePrint() {
        this.$print(this.$refs.print) // 使用
      },
      async initData() { // 初始化数据
      }
    },
    watch: {
      visible(newVal, oldVal) {
        if (newVal !== this.dialog.visible) {
          this.dialog.visible = newVal
        }
      },
      'dialog.visible'(newVal, oldVal) {
        if (!newVal) {
          this.detailInfo = {}
        }
        this.$emit('update:visible', newVal)
      },
      detailData: {
        handler: function(newVal, oldVal) {
          if (JSON.stringify(newVal) !== JSON.stringify(this.detailInfo)) {
            this.detailInfo = JSON.parse(JSON.stringify(newVal))
          }
        },
        deep: true,
        immediate: true
      }
    },
    created() {
    },
    mounted() {
    },
    filters: {
      genderFilter: function(value) {
        if (value == 1) {
          return '男'
        }

        if (value == 2) {
          return '女'
        }

        return ''
      }
    }
  }
</script>

<style lang="scss" scoped>
  .cyui-resume {
    width: 790px;
    margin: 0 auto;

    & &-hd {
      position: relative;
      padding: 100px 0 0;

      .cyui-logo {
        position: absolute;
        left: 10px;
        top: 10px;

        > img {
          display: block;
          width: 160px;

        }
      }

      .cyui-userinfo {
        display: flex;
        align-items: center;
        justify-content: center;

        .cyui-userinfo-avatar {
          display: block;
          width: 160px;
          height: 160px;
          margin-left: 130px;
          border: 5px solid #fff;
          border-radius: 100%;
          overflow: hidden;
          box-shadow: 0 0 20px #999;

          > img {
            display: block;
            width: 150px;
            height: 150px;
          }
        }

        .cyui-userinfo-right {
          position: relative;
          flex: 1;
          padding-left: 50px;
          padding-bottom: 20px;
          border-bottom: 2px solid #4b6c98;

          .cyui-userinfo-name {
            line-height: 30px;
            color: #4b6c98;
            font-size: 26px;
            font-weight: bold;
          }

          .cyui-userinfo-post {
            margin-top: 5px;
            line-height: 30px;
            color: #4b6c98;
            font-size: 20px;
            font-weight: bold;
          }
        }
      }

    }

    & &-bd {
      position: relative;
      display: flex;
      align-items: flex-start;

      &::after {
        content: " ";
        display: inline-block;
        position: absolute;
        top: 30px;
        bottom: 50px;
        left: 230px;
        border-left: 2px solid #4b6c98;
        z-index: 1;
      }

      .cyui-resume-left {
        flex-basis: 240px;
        padding: 30px 30px 50px;

        .cyui-resume-chunk {
          &:not(:last-of-type) {
            margin-bottom: 10px;
          }

          &-header {
            line-height: 40px;

            &-title {
              color: #4b6c98;
              font-size: 20px;
              font-weight: bold;
            }
          }

          &-body {
            .cyui-userinfo {
              &-item {
                display: flex;
                align-items: center;
                justify-content: center;
                min-height: 40px;
                line-height: 20px;
                color: #999;
                font-size: 14px;
                font-weight: 600;

                .cyui-userinfo-icon {
                  margin-right: 5px;

                  > img {
                    display: block;
                    width: 20px;
                  }
                }

                .cyui-userinfo-label {
                }

                .cyui-userinfo-value {
                  flex: 1;
                }
              }
            }

            .cyui-contact {
              &-item {
                display: flex;
                align-items: center;
                justify-content: center;
                min-height: 40px;
                line-height: 20px;
                color: #999;
                font-size: 14px;
                font-weight: 600;

                .cyui-contact-icon {
                  margin-right: 10px;

                  > img {
                    display: block;
                    width: 20px;
                  }
                }

                .cyui-contact-value {
                  flex: 1;
                }
              }
            }
          }
        }
      }

      .cyui-resume-right {
        flex: 1;
        padding: 0 60px 50px 50px;

        .cyui-resume-chunk {
          &:not(:last-of-type) {
            margin-bottom: 10px;
          }

          &-header {
            line-height: 40px;

            &-title {
              color: #4b6c98;
              font-size: 20px;
              font-weight: bold;
              text-align: right;
            }
          }

          &-body {
            > p {
              margin: 10px 0 0;
              line-height: 24px;
              color: #333;
              font-size: 14px;
            }
          }
        }
      }
    }
  }

</style>
